﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS.Module
{
    public partial class ucLeftMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath;
            url = url.Substring(1, url.Length - 1);
            string url1 = url.Replace(".", "/");
            string Module = url1.Substring(0, url1.IndexOf("/"));

            cmsCategoryBL catBL = new cmsCategoryBL();
            int id = 2;
            if (Request.QueryString["ID"] != null)
                id = int.Parse(Request.QueryString["ID"].ToString());
            cmsCategoryDO obj = catBL.Select(new cmsCategoryDO { CategoryID = id });
            DataTable dtCat = catBL.SelectParent(obj.CategoryID);
            if (Session["lang"].ToString() == "VN")
            {
                if (Module == "Article")
                {
                    lbl.Text = "<a href='/Category/7/Tin-tuc.aspx' title='tin-tuc'> Tin tức</a>";
                    rpt.Visible = false;
                    rpt2.Visible = true;//Cate
                    rpt2.DataSource = catBL.SelectByParentID(7, 0);
                    rpt2.DataBind();
                }
                else if (Module != "AlbumCover")
                {
                    if (obj.CategoryTypeID == 1)
                    {
                        lbl.Text = "<a href='/Category/" + dtCat.Rows[0]["CategoryID"] + "/" + FriendlyUrl(dtCat.Rows[0]["Title"].ToString()) + "'>" + dtCat.Rows[0]["Title"].ToString() + "</a>";
                        rpt.Visible = false;
                        rpt2.Visible = true;//Cate
                        rpt2.DataSource = catBL.SelectByParentID(id, 0);
                        rpt2.DataBind();
                    }
                    else if (obj.CategoryTypeID == 2)
                    {
                        lbl.Text = "<a href='/Category/" + dtCat.Rows[0]["CategoryID"] + "/" + FriendlyUrl(dtCat.Rows[0]["Title"].ToString()) + "'>" + dtCat.Rows[0]["Title"].ToString() + "</a>";
                        rpt2.Visible = false;
                        rpt.Visible = true;//About
                        rpt.DataSource = catBL.SelectByParentID(id, 0);
                        rpt.DataBind();
                    }
                }
                else if (Module == "AlbumCover")
                {
                    if (obj.ParentID == 0)
                    {
                        lbl.Text = "<a href='/AlbumCover.aspx' title='Video'>Video</a>";
                        rpt2.Visible = false;
                        rpt.Visible = false;
                        rpt3.Visible = true;//Album cover
                        rpt3.Visible = true;
                        rpt3.DataSource = catBL.SelectByParentID(12, 0);
                        rpt3.DataBind();
                    }
                    else if (obj.ParentID != 0)
                    {
                        lbl.Text = "<a href='/AlbumCover.aspx' title='Video'>Video</a>";
                        rpt2.Visible = false;
                        rpt.Visible = false;
                        rpt3.Visible = true;//Album cover
                        rpt3.Visible = true;
                        rpt3.DataSource = catBL.SelectByParentID(id, 0);
                        rpt3.DataBind();
                    }
                }
               
            }
            else
            {
                if (Module == "Article")
                {
                    lbl.Text = "<a href='/Category/7/News.aspx' title='News'> News</a>";
                    rpt.Visible = false;
                    rpt2.Visible = true;//Cate
                    rpt2.DataSource = catBL.SelectByParentID(7, 0);
                    rpt2.DataBind();
                }
                if (Module != "AlbumCover")
                {
                    if (obj.CategoryTypeID == 1)
                    {
                        lbl.Text = "<a href='/Category/" + dtCat.Rows[0]["CategoryID"] + "/" + FriendlyUrl(dtCat.Rows[0]["eTitle"].ToString()) + "'>" + dtCat.Rows[0]["eTitle"].ToString() + "</a>";
                        rpt.Visible = false;
                        rpt2.Visible = true;//Cate
                        rpt2.DataSource = catBL.SelectByParentID(id, 0);
                        rpt2.DataBind();
                    }
                    else if (obj.CategoryTypeID == 2)
                    {
                        lbl.Text = "<a href='/Category/" + dtCat.Rows[0]["CategoryID"] + "/" + FriendlyUrl(dtCat.Rows[0]["eTitle"].ToString()) + "'>" + dtCat.Rows[0]["eTitle"].ToString() + "</a>";
                        rpt2.Visible = false;
                        rpt.Visible = true;//About
                        rpt.DataSource = catBL.SelectByParentID(id, 0);
                        rpt.DataBind();
                    }
                }
                else if (Module == "AlbumCover")
                {
                    if (obj.ParentID == 0)
                    {
                        lbl.Text = "<a href='/AlbumCover.aspx' title='Video'>Video</a>";
                        rpt2.Visible = false;
                        rpt.Visible = false;
                        rpt3.Visible = true;//Album cover
                        rpt3.Visible = true;
                        rpt3.DataSource = catBL.SelectByParentID(12, 0);
                        rpt3.DataBind();
                    }
                    else if (obj.ParentID != 0)
                    {
                        lbl.Text = "<a href='/AlbumCover.aspx' title='Video'>Video</a>";
                        rpt2.Visible = false;
                        rpt.Visible = false;
                        rpt3.Visible = true;//Album cover
                        rpt3.Visible = true;
                        rpt3.DataSource = catBL.SelectByParentID(id, 0);
                        rpt3.DataBind();
                    }
                }
            }
        }
        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
    }
}